package com.tea.funct.controller;

import com.tea.common.annotation.Log;
import com.tea.common.core.controller.BaseController;
import com.tea.common.core.domain.AjaxResult;
import com.tea.common.core.page.TableDataInfo;
import com.tea.common.enums.BusinessType;
import com.tea.common.utils.poi.ExcelUtil;
import com.tea.funct.domain.TeaSettle;
import com.tea.funct.service.ITeaSettleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 结算管理Controller
 *
 * @author Sophia
 * @date 2024-05-25
 */
@RestController
@RequestMapping("/funct/settle")
public class TeaSettleController extends BaseController {
    @Autowired
    private ITeaSettleService teaSettleService;

    /**
     * 查询结算管理列表
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeaSettle teaSettle) {
        startPage();
        List<TeaSettle> list = teaSettleService.selectTeaSettleList(teaSettle);
        return getDataTable(list);
    }

    /**
     * 导出结算管理列表
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:export')")
    @Log(title = "结算管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeaSettle teaSettle) {
        List<TeaSettle> list = teaSettleService.selectTeaSettleList(teaSettle);
        ExcelUtil<TeaSettle> util = new ExcelUtil<TeaSettle>(TeaSettle.class);
        util.exportExcel(response, list, "结算管理数据");
    }

    /**
     * 获取结算管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(teaSettleService.selectTeaSettleById(id));
    }

    /**
     * 新增结算管理
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:add')")
    @Log(title = "结算管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeaSettle teaSettle) {
        return toAjax(teaSettleService.insertTeaSettle(teaSettle));
    }

    /**
     * 修改结算管理
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:edit')")
    @Log(title = "结算管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeaSettle teaSettle) {
        return toAjax(teaSettleService.updateTeaSettle(teaSettle));
    }

    /**
     * 删除结算管理
     */
    @PreAuthorize("@ss.hasPermi('funct:settle:remove')")
    @Log(title = "结算管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(teaSettleService.deleteTeaSettleByIds(ids));
    }
}
